<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>WebDAV 文件管理器</title>
    <link rel="icon" type="image/x-icon" href="/static/Icons/favicon.ico">
    <link rel="stylesheet" href="/static/all.min.css">
    <link rel="stylesheet" href="/static/toastr.min.css">
    <link rel="stylesheet" href="/static/toastr.css">
    <script src="/static/jQuery.min.js"></script>
    <script src="/static/toastr.min.js"></script>
    <style>
        :root {
            --bg-primary: #0d1117;
            --bg-secondary: #161b22;
            --bg-tertiary: #21262d;
            --text-primary: #f0f6fc;
            --text-secondary: #c9d1d9;
            --accent: #58a6ff;
            --accent-hover: #79c0ff;
            --success: #3fb950;
            --warning: #d29922;
            --error: #f85149;
            --border: #30363d;
            --window-header: #1f2428;
        }
        
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            -webkit-user-select: none; /* Chrome, Safari, Opera */
            -moz-user-select: none; /* Firefox */
            -ms-user-select: none; /* Internet Explorer/Edge */
            user-select: none;
        }
        
        body {
            background-color: var(--bg-primary);
            color: var(--text-primary);
            min-height: 100vh;
            overflow: hidden;
            background-image: 
                radial-gradient(circle at 10% 20%, rgba(41, 98, 255, 0.05) 0%, transparent 20%),
                radial-gradient(circle at 90% 80%, rgba(41, 98, 255, 0.05) 0%, transparent 20%);
        }
        
        .desktop {
            position: relative;
            width: 100vw;
            height: 100vh;
            padding: 20px;
        }
        
        .top-bar {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            height: 48px;
            background-color: var(--bg-secondary);
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 0 20px;
            border-bottom: 1px solid var(--border);
            z-index: 1000;
        }
        
        .logo {
            display: flex;
            align-items: center;
            gap: 10px;
            font-weight: 600;
            font-size: 18px;
        }
        
        .logo i {
            color: var(--accent);
        }
        
        .user-info {
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .avatar {
            width: 32px;
            height: 32px;
            border-radius: 50%;
            background: linear-gradient(135deg, var(--accent), var(--accent-hover));
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: bold;
        }
        
        .window {
            position: absolute;
            background-color: var(--bg-secondary);
            border-radius: 12px;
            overflow: hidden;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
            display: flex;
            flex-direction: column;
            min-width: 300px;
            min-height: 200px;
            border: 1px solid var(--border);
            transition: box-shadow 0.3s ease;
        }
        
        .window:hover {
            box-shadow: 0 15px 40px rgba(0, 0, 0, 0.5);
        }
        
        .window-header {
            background-color: var(--window-header);
            padding: 12px 15px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            cursor: move;
            user-select: none;
            border-bottom: 1px solid var(--border);
        }
        
        .window-title {
            display: flex;
            align-items: center;
            gap: 8px;
            font-weight: 500;
            font-size: 14px;
        }
        
        .window-controls {
            display: flex;
            gap: 8px;
        }
        
        .window-control {
            width: 12px;
            height: 12px;
            border-radius: 50%;
            cursor: pointer;
        }
        
        .close    { background-color: var(--error  ); }
        .minimize { background-color: var(--warning); }
        .maximize { background-color: var(--success); }
        
        .window-content {
            flex: 1;
            padding: 15px;
            overflow: auto;
        }
        
        /* File Browser Window */
        #fileBrowserWindow {
            width: 100vh;
            height: 85vh;
            top: 10vh;
            left: 5vh;
        }
        
        .file-browser {
            display: flex;
            flex-direction: column;
            height: 100%;
        }
        
        .browser-toolbar {
            display: flex;
            gap: 10px;
            margin-bottom: 15px;
            padding-bottom: 10px;
            border-bottom: 1px solid var(--border);
        }
        
        .browser-btn, .logout-btn {
            background-color: var(--bg-tertiary);
            border: none;
            color: var(--text-secondary);
            padding: 8px 12px;
            border-radius: 4px;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 5px;
            cursor: pointer;
            transition: all 0.2s;
            font-size: 13px;
        }
        
        .browser-btn:hover {
            background-color: var(--accent);
            color: var(--text-primary);
        }

        .logout-btn:hover {
            background-color: var(--error);
            color: var(--text-primary);
        }

        .remove-btn:hover {
            background-color: var(--error);
            color: var(--text-primary);
        }
        
        .file-list {
            flex: 1;
            background-color: var(--bg-tertiary);
            border-radius: 6px;
            overflow: auto;
            border: 1px solid var(--border);
        }
        
        .file-item {
            display: flex;
            align-items: center;
            padding: 10px 15px;
            border-bottom: 1px solid var(--border);
            cursor: pointer;
            transition: background-color 0.2s;
        }
        
        .file-item:hover {
            background-color: rgba(88, 166, 255, 0.1);
        }
        
        .file-item.selected {
            background-color: rgba(88, 166, 255, 0.2);
        }
        
        .file-icon {
            margin-right: 10px;
            width: 24px;
            text-align: center;
            color: var(--accent);
        }
        
        .file-name {
            flex: 1;
            font-size: 14px;
        }
        
        .file-size {
            color: var(--text-secondary);
            font-size: 12px;
            margin-right: 15px;
        }
        
        .file-date {
            color: var(--text-secondary);
            font-size: 12px;
        }

        .file-list.drag-over {
            border: 2px dashed var(--accent);
            background-color: rgba(88, 166, 255, 0.1);
        }
        
        .drag-overlay {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: rgba(13, 17, 23, 0.8);
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 100;
            border-radius: 6px;
            pointer-events: none;
        }
        
        .drag-text {
            font-size: 24px;
            color: var(--accent);
            text-align: center;
            padding: 20px;
            border: 3px dashed var(--accent);
            border-radius: 12px;
            background-color: var(--bg-secondary);
        }
        
        /* Loading spinner */
        .loading {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100%;
        }
        
        .spinner {
            width: 40px;
            height: 40px;
            border: 4px solid rgba(255, 255, 255, 0.1);
            border-radius: 50%;
            border-top: 4px solid var(--accent);
            animation: spin 1s linear infinite;
        }
        
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
        
        /* Text Editor Window */
        #textEditorWindow {
            width: 100vh;
            height: 85vh;
            top : 10vh;
            right: 5vh;
            display: none;
        }
        
        .editor-toolbar {
            display: flex;
            gap: 10px;
            margin-bottom: 15px;
            padding-bottom: 10px;
            border-bottom: 1px solid var(--border);
            flex-wrap: wrap;
        }
        
        .tool-btn {
            background-color: var(--bg-tertiary);
            border: none;
            color: var(--text-secondary);
            width: 30px;
            height: 30px;
            border-radius: 4px;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            transition: all 0.2s;
        }
        
        .tool-btn:hover {
            background-color: var(--accent);
            color: var(--text-primary);
        }
        
        .tool-btn.active {
            background-color: var(--accent);
            color: var(--text-primary);
        }
        
        .text-editor {
            width: 100%;
            height: 65vh;
            background-color: var(--bg-tertiary);
            border: 1px solid var(--border);
            border-radius: 6px;
            padding: 12px;
            color: var(--text-primary);
            resize: none;
            font-family: 'Consolas', monospace;
            line-height: 1.5;
            tab-size: 4;
        }
        
        .text-editor:focus {
            outline: none;
            border-color: var(--accent);
        }
        
        .editor-actions {
            display: flex;
            justify-content: flex-end;
            gap: 10px;
            margin-top: 15px;
        }
        
        .action-btn {
            padding: 8px 16px;
            border-radius: 4px;
            border: none;
            cursor: pointer;
            font-size: 14px;
            transition: all 0.2s;
        }
        
        .btn-primary {
            background-color: var(--accent);
            color: white;
        }
        
        .btn-primary:hover {
            background-color: var(--accent-hover);
        }
        
        .btn-secondary {
            background-color: var(--bg-tertiary);
            color: var(--text-primary);
        }
        
        .btn-secondary:hover {
            background-color: #2f3640;
        }
        
        /* Media Player Window */
        #mediaPlayerWindow {
            top : 10vh;
            right: 5vh;
            display: none;
        }
        
        .media-player {
            width: 100%;
            height: 100%;
            display: flex;
            flex-direction: column;
            gap: 15px;
        }
        
        .video-container {
            background-color: var(--bg-tertiary);
            width: 100%;
            height: 65vh;
            position: relative;
            border-radius: 6px;
            overflow: hidden;
            display: flex;
        }
        
        .video-element {
            position: relative;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 100%;
            object-fit: contain;
            display: none;
        }
        
        .video-placeholder {
            width: 100%;
            height: 100%;
            display: flex;
            align-items: center;
            justify-content: center;
            flex-direction: column;
            gap: 5vh;
            color: var(--text-secondary);
        }
        
        .player-controls {
            display: flex;
            align-items: center;
            justify-content: space-between;
        }
        
        .control-btn {
            background-color: var(--bg-tertiary);
            border: none;
            color: var(--text-primary);
            width: 5vh;
            height: 5vh;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            transition: all 0.2s;
        }
        
        .control-btn:hover {
            background-color: var(--accent);
        }
        
        .progress-container {
            flex: 1;
            display: flex;
            align-items: center;
            gap: 10px;
            margin: 0 20px;
        }
        
        .progress-time {
            font-size: 12px;
            color: var(--text-secondary);
            min-width: 40px;
            text-align: center;
        }
        
        .progress-bar {
            flex: 1;
            height: 5px;
            background-color: var(--bg-tertiary);
            border-radius: 3px;
            overflow: hidden;
            cursor: pointer;
        }
        
        .progress {
            height: 100%;
            background-color: var(--accent);
            width: 0%;
            border-radius: 3px;
            transition: width 0.1s;
        }
        
        .volume-control {
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .volume-slider {
            width: 80px;
            appearance: none;
            -webkit-appearance: none;
            height: 5px;
            background: var(--bg-tertiary);
            border-radius: 3px;
            outline: none;
        }
        
        .volume-slider::-webkit-slider-thumb {
            -webkit-appearance: none;
            appearance: none;
            width: 15px;
            height: 15px;
            border-radius: 50%;
            background: var(--accent);
            cursor: pointer;
        }
        
        .volume-slider::-moz-range-thumb {
            width: 15px;
            height: 15px;
            border-radius: 50%;
            background: var(--accent);
            cursor: pointer;
        }
        
        /* Image Viewer Window */
        #imageViewerWindow {
            width: 100vh;
            height: auto;
            top : 10vh;
            right: 5vh;
            display: none;
        }
        
        .image-viewer {
            width: 100%;
            max-height: 100%;
            display: flex;
            flex-direction: column;
            gap: 15px;
        }
        
        .image-container {
            background-color: var(--bg-tertiary);
            border-radius: 6px;
            overflow: hidden;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        
        .image-placeholder {
            width: 100%;
            height: 100%;
            display: flex;
            align-items: center;
            justify-content: center;
            flex-direction: column;
            gap: 15px;
            color: var(--text-secondary);
        }
        
        .nav-btn {
            background-color: var(--bg-tertiary);
            border: none;
            color: var(--text-primary);
            width: 40px;
            height: 40px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            transition: all 0.2s;
        }
        
        .nav-btn:hover {
            background-color: var(--accent);
        }
        
        .image-info {
            text-align: center;
            font-size: 14px;
            color: var(--text-secondary);
        }
        
        /* Fullscreen styles */
        .fullscreen .video-container {
            position: fixed;
            top: 0;
            left: 0;
            width: 100vw;
            height: 100vh;
            z-index: 2000;
            border-radius: 0;
        }
        
        .fullscreen .player-controls {
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            padding: 15px;
            background-color: rgba(13, 17, 23, 0.8);
            z-index: 2001;
        }
        
        /* 自定义提示框样式 */
        .custom-alert {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background-color: var(--bg-secondary);
            border: 1px solid var(--border);
            border-radius: 8px;
            padding: 20px;
            z-index: 3000;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
            min-width: 300px;
        }
        
        .custom-alert-content {
            margin-bottom: 20px;
        }
        
        .custom-alert-buttons {
            display: flex;
            justify-content: flex-end;
            gap: 10px;
        }
        
        .custom-alert-btn {
            padding: 8px 16px;
            border-radius: 4px;
            border: none;
            cursor: pointer;
            font-size: 14px;
        }
        
        .custom-alert-btn-primary {
            background-color: var(--accent);
            color: white;
        }
        
        .custom-alert-overlay {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: rgba(0, 0, 0, 0.5);
            z-index: 2999;
        }
        
        /* 右键菜单样式 */
        .context-menu {
            position: fixed;
            background-color: var(--bg-secondary);
            border: 1px solid var(--border);
            border-radius: 6px;
            padding: 5px 0;
            z-index: 2000;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
            min-width: 150px;
            display: none;
        }
        
        .context-menu-item {
            padding: 8px 15px;
            cursor: pointer;
            font-size: 14px;
            display: flex;
            align-items: center;
            gap: 8px;
        }
        
        .context-menu-item:hover {
            background-color: var(--accent);
        }
        
        /* 上传文件样式 */
        .upload-modal {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background-color: var(--bg-secondary);
            border: 1px solid var(--border);
            border-radius: 8px;
            padding: 20px;
            z-index: 3000;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
            min-width: 400px;
        }
        
        .upload-modal-header {
            margin-bottom: 15px;
            font-weight: 600;
        }
        
        .upload-modal-body {
            margin-bottom: 20px;
        }
        
        .upload-input {
            width: 100%;
            padding: 10px;
            background-color: var(--bg-tertiary);
            border: 1px solid var(--border);
            border-radius: 4px;
            color: var(--text-primary);
            margin-bottom: 15px;
        }
        
        .upload-file-input {
            display: none;
        }
        
        .upload-modal-footer {
            display: flex;
            justify-content: flex-end;
            gap: 10px;
        }
        
        .upload-btn {
            padding: 8px 16px;
            border-radius: 4px;
            border: none;
            cursor: pointer;
            font-size: 14px;
        }
        
        .upload-btn-primary {
            background-color: var(--accent);
            color: white;
        }
        
        .upload-btn-secondary {
            background-color: var(--bg-tertiary);
            color: var(--text-primary);
        }
        
        /* 音频播放器特定样式 */
        .audio-player {
            width: 100%;
            height: 14vh;
            background-color: var(--bg-tertiary);
            border-radius: 6px;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 0 20px;
        }
        
        /* 音频信息样式 */
        .audio-info {
            text-align: center;
            font-size: 14px;
            color: var(--text-secondary);
            margin-top: -10px;
        }

         /* 确认对话框样式 */
        .confirm-dialog {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background-color: var(--bg-secondary);
            border: 1px solid var(--border);
            border-radius: 8px;
            padding: 20px;
            z-index: 3000;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
            min-width: 300px;
        }
        
        .confirm-dialog-content {
            margin-bottom: 20px;
        }
        
        .confirm-dialog-buttons {
            display: flex;
            justify-content: flex-end;
            gap: 10px;
        }
        
        .confirm-dialog-btn {
            padding: 8px 16px;
            border-radius: 4px;
            border: none;
            cursor: pointer;
            font-size: 14px;
        }
        
        .confirm-dialog-btn-primary {
            background-color: var(--accent);
            color: white;
        }
        
        .confirm-dialog-btn-secondary {
            background-color: var(--bg-tertiary);
            color: var(--text-primary);
        }
        
        .confirm-dialog-overlay {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: rgba(0, 0, 0, 0.5);
            z-index: 2999;
        }

        .custom-prompt {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background-color: var(--bg-secondary);
            border: 1px solid var(--border);
            border-radius: 8px;
            padding: 20px;
            z-index: 3000;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
            min-width: 350px;
            max-width: 90vw;
        }

        .custom-prompt-header {
            margin-bottom: 15px;
            font-weight: 600;
            font-size: 16px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .custom-prompt-close {
            background: none;
            border: none;
            color: var(--text-secondary);
            cursor: pointer;
            font-size: 18px;
        }

        .custom-prompt-close:hover {
            color: var(--text-primary);
        }

        .custom-prompt-body {
            margin-bottom: 20px;
        }

        .custom-prompt-input {
            width: 100%;
            padding: 10px 12px;
            background-color: var(--bg-tertiary);
            border: 1px solid var(--border);
            border-radius: 4px;
            color: var(--text-primary);
            font-size: 14px;
            margin-top: 8px;
        }

        .custom-prompt-input:focus {
            outline: none;
            border-color: var(--accent);
        }

        .custom-prompt-footer {
            display: flex;
            justify-content: flex-end;
            gap: 10px;
        }

        .custom-prompt-btn {
            padding: 8px 16px;
            border-radius: 4px;
            border: none;
            cursor: pointer;
            font-size: 14px;
            transition: all 0.2s;
        }

        .custom-prompt-btn-primary {
            background-color: var(--accent);
            color: white;
        }

        .custom-prompt-btn-primary:hover {
            background-color: var(--accent-hover);
        }

        .custom-prompt-btn-secondary {
            background-color: var(--bg-tertiary);
            color: var(--text-primary);
        }

        .custom-prompt-btn-secondary:hover {
            background-color: #2f3640;
        }

        .custom-prompt-overlay {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: rgba(0, 0, 0, 0.5);
            z-index: 3000;
        }

        .upload-list-container {
            position: fixed;
            bottom: 20px;
            right: 20px;
            width: 350px;
            max-height: 400px;
            background-color: var(--bg-secondary);
            border: 1px solid var(--border);
            border-radius: 8px;
            box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
            z-index: 1001;
            display: none;
            overflow: hidden;
        }

        .upload-list-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 12px 15px;
            background-color: var(--window-header);
            border-bottom: 1px solid var(--border);
            font-weight: 600;
        }

        .upload-list-close {
            background: none;
            border: none;
            color: var(--text-secondary);
            cursor: pointer;
            font-size: 16px;
        }

        .upload-list-close:hover {
            color: var(--text-primary);
        }

        .upload-list-items {
            max-height: 350px;
            overflow-y: auto;
        }

        .upload-item {
            padding: 12px 15px;
            border-bottom: 1px solid var(--border);
            display: flex;
            flex-direction: column;
        }

        .upload-item:last-child {
            border-bottom: none;
        }

        .upload-item-info {
            display: flex;
            justify-content: space-between;
            margin-bottom: 8px;
        }

        .upload-item-name {
            font-size: 14px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            max-width: 70%;
        }

        .upload-item-percent {
            font-size: 14px;
            color: var(--text-secondary);
        }

        .upload-progress-container {
            width: 100%;
            height: 6px;
            background-color: var(--bg-tertiary);
            border-radius: 3px;
            overflow: hidden;
        }

        .upload-progress-bar {
            height: 100%;
            background-color: var(--accent);
            width: 0%;
            transition: width 0.3s ease;
        }

        .upload-item-error {
            color: var(--error);
            font-size: 12px;
            margin-top: 5px;
        }

        /* 上传按钮悬停提示 */
        #uploadBtn {
            position: relative;
        }

        #uploadBtn:hover::after {
            content: "显示上传队列";
            position: absolute;
            bottom: -30px;
            left: 50%;
            transform: translateX(-50%);
            background-color: var(--bg-tertiary);
            color: var(--text-primary);
            padding: 5px 10px;
            border-radius: 4px;
            font-size: 12px;
            white-space: nowrap;
            z-index: 100;
        }
        
        /* Responsive adjustments */
        @media (max-width: 750px) {
            .window {
                margin-bottom: 20px;
                width: 94% !important;
                height: 20vh;
                top: auto !important;
                left: auto !important;
                right: auto !important;
                bottom: auto !important;
                transform: none !important;
            }
            
            .desktop {
                display: flex;
                flex-direction: column;
                padding: 70px 20px 20px 20px;
            }
        }
    </style>
</head>
<body>
    <!-- 上传列表容器 -->
    <div class="upload-list-container" id="uploadListContainer">
        <div class="upload-list-header">
            <span>上传队列</span>
            <button class="upload-list-close" id="uploadListClose">
                <i class="fas fa-times"></i>
            </button>
        </div>
        <div class="upload-list-items" id="uploadListItems"></div>
    </div>
    <div class="top-bar">
        <div class="logo">
            <i class="fas fa-cloud"></i>
            <span>WebDAV 文件管理器</span>
        </div>
        <div class="user-info">
            <span>{{ username }}</span>
            <div class="avatar">{{ username[0]|upper }}</div>
            <button type="button" class="logout-btn" id="LogoutBtn" title="登出"><i class="fas fa-sign-out-alt"></i> 登出 </button>
        </div>
    </div>
    <div class="desktop">
        <!-- File Browser Window -->
        <div class="window" id="fileBrowserWindow">
            <div class="window-header">
                <div class="window-title">
                    <i class="fas fa-folder"></i>
                    <span id="fileBrowserWindowTitle">文件浏览器</span>
                </div>
                <div class="window-controls">
                    <div class="window-control minimize" style="display: none;"></div>
                    <div class="window-control maximize"></div>
                    <div class="window-control close"    style="display: none;"></div>
                </div>
            </div>
            <div class="window-content">
                <div class="file-browser">
                    <div class="browser-toolbar">
                        <button class="browser-btn" id="uploadBtn" title="上传文件">
                            <i class="fas fa-upload"></i>
                            <span>上传</span>
                        </button>
                        <button class="browser-btn" id="createFolderBtn" title="新建文件夹">
                            <i class="fas fa-folder-plus"></i>
                            <span>新建文件夹</span>
                        </button>
                        <button class="browser-btn" id="createFileBtn" title="新建文件">
                            <i class="fas fa-file"></i>
                            <span>新建文件</span>
                        </button>
                        <button class="browser-btn" id="renameBtn" title="重命名文件/文件夹">
                            <i class="fas fa-i-cursor"></i>
                            <span>重命名</span>
                        </button>
                        <button class="browser-btn" id="refreshBtn" title="刷新">
                            <i class="fas fa-sync-alt"></i>
                            <span>刷新</span>
                        </button>
                        <button class="browser-btn" id="downloadBtn" title="下载">
                            <i class="fas fa-download"></i>
                            <span>下载</span>
                        </button>
                        <button class="browser-btn remove-btn" id="deleteBtn" title="删除">
                            <i class="fas fa-trash-alt"></i>
                            <span>删除</span>
                        </button>
                    </div>
                    <div class="file-list" id="fileList">
                        <div class="loading">
                            <div class="spinner"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <input type="file" id="uploadInput" multiple style="display: none;">
        <!-- Text Editor Window -->
        <div class="window" id="textEditorWindow">
            <div class="window-header">
                <div class="window-title">
                    <i class="fas fa-file-alt"></i>
                    <span>文本编辑器</span>
                </div>
                <div class="window-controls">
                    <div class="window-control minimize" style="display: none;"></div>
                    <div class="window-control maximize" style="display: none;"></div>
                    <div class="window-control close"></div>
                </div>
            </div>
            <div class="window-content">
            <!--
                <div class="editor-toolbar">
                    <button class="tool-btn" id="boldBtn"        title="粗体">    <i class="fas fa-bold"></i></button>
                    <button class="tool-btn" id="italicBtn"      title="斜体">    <i class="fas fa-italic"></i></button>
                    <button class="tool-btn" id="underlineBtn"   title="下划线">  <i class="fas fa-underline"></i></button>
                    <button class="tool-btn" id="listBtn"        title="列表">    <i class="fas fa-list-ul"></i></button>
                    <button class="tool-btn" id="leftAlignBtn"   title="左对齐">  <i class="fas fa-align-left"></i></button>
                    <button class="tool-btn" id="centerAlignBtn" title="居中">    <i class="fas fa-align-center"></i></button>
                    <button class="tool-btn" id="rightAlignBtn"  title="右对齐">  <i class="fas fa-align-right"></i></button>
                    <button class="tool-btn" id="fullscreenBtn"  title="全屏编辑"><i class="fas fa-expand"></i></button>
                </div>
            -->
                <textarea class="text-editor" id="textEditor" placeholder=""></textarea>
                <div class="editor-actions">
                    <button class="action-btn btn-secondary" id="cancelEditBtn">取消</button>
                    <button class="action-btn btn-primary" id="saveFileBtn">保存</button>
                </div>
            </div>
        </div>

        <!-- Media Player Window -->
        <div class="window" id="mediaPlayerWindow">
            <div class="window-header">
                <div class="window-title">
                    <i class="fas fa-play-circle"></i>
                    <span id="mediaPlayerWindowTitle">媒体播放器</span>
                </div>
                <div class="window-controls">
                    <div class="window-control minimize" style="display: none;"></div>
                    <div class="window-control maximize" style="display: none;"></div>
                    <div class="window-control close"></div>
                </div>
            </div>
            <div class="window-content">
                <div class="media-player">
                    <div class="video-container" id="videoContainer">
                        <video id="videoPlayer" class="video-element"></video>
                        <div class="video-placeholder" id="videoPlaceholder">
                            <i class="fas fa-play-circle" style="font-size: 48px;"></i>
                        </div>
                    </div>
                    <div class="audio-player" id="audioContainer" style="display: none;">
                        <i class="fas fa-music" style="font-size: 32px; margin-right: 15px;"></i>
                        <div class="progress-container" style="flex: 1;">
                            <div class="audio-info" id="mediaInfo"></div>
                        </div>
                    </div>
                    <div class="player-controls">
                        <button class="control-btn" id="prevBtn">
                            <i class="fas fa-fast-backward"></i>
                        </button>
                        <button class="control-btn" id="playBtn">
                            <i class="fas fa-play"></i>
                        </button>
                        <button class="control-btn" id="nextBtn">
                            <i class="fas fa-fast-forward"></i>
                        </button>
                        <div class="progress-container">
                            <span class="progress-time" id="currentTime">0:00</span>
                            <div class="progress-bar" id="progressBar">
                                <div class="progress" id="progress"></div>
                            </div>
                            <span class="progress-time" id="totalTime">0:00</span>
                        </div>
                        <button class="control-btn" id="fullscreenMediaBtn">
                            <i class="fas fa-expand"></i>
                        </button>
                        <div class="volume-control">
                            <button class="control-btn" id="muteBtn">
                                <i class="fas fa-volume-up"></i>
                            </button>
                            <input type="range" class="volume-slider" id="volumeSlider" min="0" max="1" step="0.01" value="1">
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <!-- Image Viewer Window -->
        <div class="window" id="imageViewerWindow">
            <div class="window-header">
                <div class="window-title">
                    <i class="fas fa-image"></i>
                    <span>图片预览</span>
                </div>
                <div class="window-controls">
                    <div class="window-control minimize" style="display: none;"></div>
                    <div class="window-control maximize"></div>
                    <div class="window-control close"></div>
                </div>
            </div>
            <div class="window-content">
                <div class="image-viewer">
                    <div class="image-container">
                        <img id="imageViewer" style="max-width: 100%; max-height: 75vh; display: none; object-fit: contain;">
                        <div class="image-placeholder" id="imagePlaceholder">
                            <i class="fas fa-image" style="font-size: 48px;"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        function showConfirm(message, callback) {
            const overlay = document.createElement('div');
            overlay.className = 'confirm-dialog-overlay';
            
            const confirmBox = document.createElement('div');
            confirmBox.className = 'confirm-dialog';
            confirmBox.innerHTML = `
                <div class="confirm-dialog-content">${message}</div>
                <div class="confirm-dialog-buttons">
                    <button class="confirm-dialog-btn confirm-dialog-btn-secondary" id="confirmCancelBtn">取消</button>
                    <button class="confirm-dialog-btn confirm-dialog-btn-primary"   id="confirmOkBtn">确定</button>
                </div>
            `;
            
            document.body.appendChild(overlay);
            document.body.appendChild(confirmBox);
            
            document.getElementById('confirmCancelBtn').addEventListener('click', function() {
                document.body.removeChild(overlay);
                document.body.removeChild(confirmBox);
                callback(false);
            });
            
            document.getElementById('confirmOkBtn').addEventListener('click', function() {
                document.body.removeChild(overlay);
                document.body.removeChild(confirmBox);
                callback(true);
            });
        }

        // 显示自定义prompt
        function showPrompt(message, defaultValue = '', callback) {
            // 创建遮罩层
            const overlay     = document.createElement('div');
            overlay.className = 'custom-prompt-overlay';
            
            // 创建prompt容器
            const promptBox     = document.createElement('div');
            promptBox.className = 'custom-prompt';
            
            // 生成HTML内容
            promptBox.innerHTML = `
                <div class="custom-prompt-header">
                    <span>${message}</span>
                    <button class="custom-prompt-close">&times;</button>
                </div>
                <div class="custom-prompt-body">
                    <input type="text" class="custom-prompt-input" value="${defaultValue}" autofocus>
                </div>
                <div class="custom-prompt-footer">
                    <button class="custom-prompt-btn custom-prompt-btn-secondary" id="promptCancelBtn">取消</button>
                    <button class="custom-prompt-btn custom-prompt-btn-primary" id="promptOkBtn">确定</button>
                </div>
            `;
            
            // 添加到页面
            document.body.appendChild(overlay);
            document.body.appendChild(promptBox);
            
            // 获取输入框和按钮元素
            const inputEl   = promptBox.querySelector('.custom-prompt-input');
            const cancelBtn = promptBox.querySelector('#promptCancelBtn');
            const okBtn     = promptBox.querySelector('#promptOkBtn');
            const closeBtn  = promptBox.querySelector('.custom-prompt-close');
            
            // 聚焦输入框并选中文本
            inputEl.focus();
            inputEl.select();
            
            // 关闭函数
            function closePrompt(value) {
                document.body.removeChild(overlay);
                document.body.removeChild(promptBox);
                if (callback) {
                    callback(value);
                }
            }
            
            // 确定按钮事件
            okBtn.addEventListener('click', function() {
                closePrompt(inputEl.value);
            });
            
            // 取消按钮事件
            cancelBtn.addEventListener('click', function() {
                closePrompt(null);
            });
            
            // 关闭按钮事件
            closeBtn.addEventListener('click', function() {
                closePrompt(null);
            });
            
            // 遮罩层点击事件
            overlay.addEventListener('click', function() {
                closePrompt(null);
            });
            
            // 输入框回车事件
            inputEl.addEventListener('keypress', function(e) {
                if (e.key === 'Enter') {
                    closePrompt(inputEl.value);
                }
            });
            
            // ESC键关闭
            document.addEventListener('keydown', function handleEsc(e) {
                if (e.key === 'Escape') {
                    closePrompt(null);
                    document.removeEventListener('keydown', handleEsc);
                }
            });
        }
        document.addEventListener('DOMContentLoaded', function() {
            // 获取所有窗口
            const windows     = document.querySelectorAll('.window');
            const fileBrowser = document.getElementById('fileBrowserWindow');
            const textEditor  = document.getElementById('textEditorWindow');
            const mediaPlayer = document.getElementById('mediaPlayerWindow');
            const imageViewer = document.getElementById('imageViewerWindow');
            
            // 文件浏览器中的文件列表
            const fileList = document.getElementById('fileList');
            
            // 当前路径和选中的文件
            let currentPath  = (window.location.pathname + '/').replace('//', '/');
            let selectedFile = null;
            let currentFiles = [];
            
            // 初始化 - 加载根目录
            loadDirectory(currentPath);

            toastr.options.timeOut = 2000;
            toastr.options.positionClass = 'toast-bottom-left';
            
            // 创建拖放覆盖层
            const dragOverlay = document.createElement('div');
            dragOverlay.className = 'drag-overlay';
            dragOverlay.innerHTML = '<div class="drag-text">拖放到此处上传</div>';
            dragOverlay.style.display = 'none';
            fileList.parentNode.appendChild(dragOverlay);

            // 拖放事件处理
            fileList.addEventListener('dragover', function(e) {
                e.preventDefault();
                e.stopPropagation();
                fileList.classList.add('drag-over');
                dragOverlay.style.display = 'flex';
            });

            fileList.addEventListener('dragleave', function(e) {
                e.preventDefault();
                e.stopPropagation();
                
                // 只有当鼠标离开文件列表区域时才移除样式
                const rect = fileList.getBoundingClientRect();
                if (
                    e.clientX < rect.left || 
                    e.clientX > rect.right || 
                    e.clientY < rect.top || 
                    e.clientY > rect.bottom
                ) {
                    fileList.classList.remove('drag-over');
                    dragOverlay.style.display = 'none';
                }
            });

            fileList.addEventListener('drop', function(e) {
                e.preventDefault();
                e.stopPropagation();
                
                fileList.classList.remove('drag-over');
                dragOverlay.style.display = 'none';
                
                const items = e.dataTransfer.items;
                if (!items || items.length === 0) return;
                
                // 显示上传列表
                document.getElementById('uploadListContainer').style.display = 'block';
                
                // 处理拖放的文件和文件夹
                processDroppedItems(items);
            });

            // 处理拖放的文件和文件夹
            function processDroppedItems(items) {
                // 显示上传列表
                document.getElementById('uploadListContainer').style.display = 'block';
                
                // 处理拖放的文件和文件夹
                for (let i = 0; i < items.length; i++) {
                    const item = items[i];
                    
                    if (item.kind === 'file') {
                        const entry = item.webkitGetAsEntry ? item.webkitGetAsEntry() : null;
                        
                        if (entry && entry.isDirectory) {
                            // 处理文件夹
                            processDirectoryEntry(entry);
                        } else {
                            // 处理文件
                            const file = item.getAsFile();
                            if (file) {
                                addFileToUploadQueue(file);
                            }
                        }
                    }
                }
                
                // 开始上传
                processUploadQueue();
            }

            // 处理文件夹上传
            function processDirectoryEntry(entry) {
                if (!entry) return;
                
                // 为文件夹创建特定标识
                const dirId = 'dir-' + Date.now() + Math.random().toString(36).substr(2, 5);
                
                // 在UI中添加文件夹上传项
                const uploadListItems = document.getElementById('uploadListItems');
                const dirItemElement = document.createElement('div');
                dirItemElement.className = 'upload-item';
                dirItemElement.id = `upload-item-${dirId}`;
                dirItemElement.innerHTML = `
                    <div class="upload-item-info">
                        <div class="upload-item-name" title="${entry.name}">${entry.name}/</div>
                        <div class="upload-item-percent">准备中...</div>
                    </div>
                    <div class="upload-progress-container">
                        <div class="upload-progress-bar" id="progress-bar-${dirId}"></div>
                    </div>
                    <div class="upload-item-error" id="upload-error-${dirId}"></div>
                `;
                
                uploadListItems.appendChild(dirItemElement);
                
                // 读取文件夹内容
                readDirectoryRecursively(entry, entry.name, dirId);
            }

            // 递归读取文件夹内容
            function readDirectoryRecursively(entry, basePath, dirId) {
                const dirReader = entry.createReader();
                const filesToUpload = [];
                
                function readEntries() {
                    dirReader.readEntries(function(entries) {
                        if (entries.length === 0) {
                            // 所有条目已读取完毕，开始上传
                            if (filesToUpload.length > 0) {
                                uploadDirectoryFiles(filesToUpload, basePath, dirId);
                            } else {
                                // 空文件夹处理
                                updateUploadStatus(dirId, 'completed', 100);
                            }
                            return;
                        }
                        
                        // 处理当前批次的条目
                        let processedCount = 0;
                        
                        entries.forEach(function(entry) {
                            if (entry.isDirectory) {
                                // 递归处理子文件夹
                                readDirectoryRecursively(entry, basePath + '/' + entry.name, dirId);
                                processedCount++;
                                
                                // 检查是否处理完所有条目
                                if (processedCount === entries.length) {
                                    readEntries(); // 继续读取更多条目
                                }
                            } else {
                                // 获取文件并添加到上传列表
                                entry.file(function(file) {
                                    // 保存文件的完整路径信息
                                    file.fullPath = basePath + '/' + file.name;
                                    filesToUpload.push(file);
                                    processedCount++;
                                    
                                    // 检查是否处理完所有条目
                                    if (processedCount === entries.length) {
                                        readEntries(); // 继续读取更多条目
                                    }
                                }, function(error) {
                                    console.error('读取文件出错:', error);
                                    processedCount++;
                                    
                                    // 检查是否处理完所有条目
                                    if (processedCount === entries.length) {
                                        readEntries(); // 继续读取更多条目
                                    }
                                });
                            }
                        });
                    }, function(error) {
                        console.error('读取文件夹出错:', error);
                        updateUploadStatus(dirId, 'error', null, '读取文件夹失败: ' + error.message);
                    });
                }
                
                readEntries();
            }

            // 上传文件夹中的文件
            function uploadDirectoryFiles(files, basePath, dirId) {
                if (files.length === 0) {
                    updateUploadStatus(dirId, 'completed', 100);
                    return;
                }
                
                let uploadedCount = 0;
                const totalFiles = files.length;
                
                // 更新UI显示文件数量
                const percentText = document.querySelector(`#upload-item-${dirId} .upload-item-percent`);
                if (percentText) {
                    percentText.textContent = `0/${totalFiles} 个文件`;
                }
                
                // 逐个上传文件
                files.forEach(function(file) {
                    const filePath = currentPath + (currentPath.endsWith('/') ? '' : '/') + file.fullPath;
                    const xhr = new XMLHttpRequest();
                    
                    xhr.upload.addEventListener('progress', function(e) {
                        if (e.lengthComputable) {
                            // 计算整体进度 (已上传文件数 + 当前文件进度)
                            const fileProgress = (e.loaded / e.total) * (1 / totalFiles);
                            const totalProgress = (uploadedCount / totalFiles) + fileProgress;
                            updateUploadProgress(dirId, totalProgress * 100);
                        }
                    });
                    
                    xhr.addEventListener('load', function() {
                        uploadedCount++;
                        
                        // 更新文件计数
                        if (percentText) {
                            percentText.textContent = `${uploadedCount}/${totalFiles} 个文件`;
                        }
                        
                        if (xhr.status >= 200 && xhr.status < 300) {
                            if (uploadedCount === totalFiles) {
                                // 所有文件上传完成
                                updateUploadStatus(dirId, 'completed', 100);
                                
                                // 刷新文件列表
                                loadDirectory(currentPath);
                            }
                        } else {
                            updateUploadStatus(dirId, 'error', null, `上传失败: ${xhr.statusText}`);
                        }
                    });
                    
                    xhr.addEventListener('error', function() {
                        uploadedCount++;
                        updateUploadStatus(dirId, 'error', null, '网络错误');
                    });
                    
                    xhr.open('PUT', filePath, true);
                    xhr.send(file);
                });
            }

            // 为每个窗口添加拖动功能
            windows.forEach(window => {
                const header = window.querySelector('.window-header');
                let isDragging = false;
                let startX, startY, initialX, initialY;
                
                header.addEventListener('mousedown', function(e) {
                    isDragging = true;
                    startX = e.clientX;
                    startY = e.clientY;
                    initialX = window.offsetLeft;
                    initialY = window.offsetTop;
                    window.style.zIndex = 1000;
                    
                    // 降低其他窗口的z-index
                    windows.forEach(w => {
                        if (w !== window) {
                            w.style.zIndex = 1;
                        }
                    });
                });
                
                document.addEventListener('mousemove', function(e) {
                    if (!isDragging) return;
                    
                    const dx = e.clientX - startX;
                    const dy = e.clientY - startY;
                    
                    window.style.left = `${initialX + dx}px`;
                    window.style.top  = `${initialY + dy}px`;
                });
                
                document.addEventListener('mouseup', function() {
                    isDragging = false;
                });
                
                // 窗口控制按钮功能
                const closeBtn    = window.querySelector('.close');
                const minimizeBtn = window.querySelector('.minimize');
                const maximizeBtn = window.querySelector('.maximize');
                
                // 文件浏览器窗口禁用关闭按钮
                if (window.id === 'fileBrowserWindow') {
                    closeBtn.style.display = 'none';
                } else {
                    closeBtn.addEventListener('click', function() {
                        window.style.display = 'none';
                        // 停止媒体播放
                        if (window.id === 'mediaPlayerWindow') {
                            removeMediaPlayerEventListeners();
                            const videoPlayer = document.getElementById('videoPlayer');
                            const audioPlayer = document.getElementById('audioPlayer');
                            try {
                                videoPlayer.pause();
                                audioPlayer.pause();
                                videoPlayer.src = '';
                                audioPlayer.src = '';
                            }
                            catch (e) {
                                videoPlayer.src = '';
                            }
                            
                        }
                    });
                }
                
                minimizeBtn.addEventListener('click', function() {
                    const content = window.querySelector('.window-content');
                    content.style.display = content.style.display === 'none' ? 'flex' : 'none';
                });
                
                maximizeBtn.addEventListener('click', function() {
                    if (window.style.width === '96vw') {
                        window.style.width  = '';
                        window.style.height = '';
                        window.style.top  = '';
                        window.style.left = '';
                        window.style.transform = '';
                    } else {
                        window.style.width  = '96vw';
                        window.style.height = '85vh';
                        window.style.top  = '52%';
                        window.style.left = '50%';
                        window.style.transform = 'translate(-50%, -50%)';
                    }
                });
            });
            
            // 加载目录内容
            function loadDirectory(path) {
                fileList.innerHTML = '<div class="loading"><div class="spinner"></div></div>';
                history.pushState(null, '', path);
                fetch(path, {
                    method: 'PROPFIND',
                })
                .then(response => {
                    if (!response.ok) {
                        throw new Error('Network response was not ok');
                    }
                    return response.text();
                })
                .then(xmlData => {
                    document.getElementById('fileBrowserWindowTitle').innerHTML = `文件浏览器 - ${decodeURIComponent(path)}`;
                    parseDirectoryXML(xmlData, path);
                })
                .catch(error => {
                    console.error('Error loading directory:', error);
                    fileList.innerHTML = '<div class="file-item">加载失败: ' + error.message + '</div>';
                });
                selectedFile = null;
            }
            
            // 解析目录XML
            function parseDirectoryXML(xmlData, path) {
                xmlData = xmlData.replace(/&(?!amp;|lt;|gt;|quot;|#)/g, '&amp;');
                const parser = new DOMParser();
                const xmlDoc = parser.parseFromString(xmlData, "text/xml");
                const responses = xmlDoc.getElementsByTagName("D:response");
                
                currentFiles = [];
                fileList.innerHTML = '';
                
                // 添加返回上级目录选项（如果不是根目录）
                if (path !== '/') {
                    const parentItem = document.createElement('div');
                    parentItem.className =  'file-item';
                    parentItem.setAttribute('data-type', 'folder');
                    parentItem.setAttribute('data-path', getParentPath(path));
                    
                    parentItem.innerHTML = `
                        <div class="file-icon"><i class="fas fa-level-up-alt"></i></div>
                        <div class="file-name">返回上级目录</div>
                        <div class="file-size"></div>
                        <div class="file-date"></div>
                    `;
                    
                    parentItem.addEventListener('dblclick', function() {
                        currentPath = getParentPath(path);
                        loadDirectory(currentPath);
                    });
                    
                    fileList.appendChild(parentItem);
                }
                
                // 解析目录内容
                for (let i = 0; i < responses.length; i++) {
                    const response = responses[i];
                    const href     = response.getElementsByTagName("D:href")[0].textContent;

                    // 跳过当前目录本身
                    if (decodeURIComponent(path) === href || (path === '/' && href === '/')) {
                        continue;
                    }
                    const propstat = response.getElementsByTagName("D:propstat")[0];
                    const prop     = propstat.getElementsByTagName("D:prop")[0];
                    const displayName  = prop.getElementsByTagName("D:displayname")[0].textContent;
                    const resourceType = prop.getElementsByTagName("D:resourcetype")[0];
                    const isDir        = resourceType.getElementsByTagName("D:collection").length > 0;
                    const size         = prop.getElementsByTagName("D:getcontentlength")[0]?.textContent || '';
                    const modified     = prop.getElementsByTagName("D:getlastmodified")[0]?.textContent || '';
                    const fileItem     = document.createElement('div');
                    fileItem.className =  'file-item';
                    fileItem.setAttribute('data-type', isDir ? 'folder' : 'file');
                    fileItem.setAttribute('data-path', href);
                    
                    // 获取文件扩展名
                    let extension = '';
                    let iconClass = 'fa-file';
                    if (!isDir) {
                        const parts = displayName.split('.');
                        extension = parts.length > 1 ? parts.pop().toLowerCase() : '';
                        
                        Extension_Text       = ['txt', 'log', 'ini'];
                        Extension_Code       = ['md', 'htm', 'html', 'css', 'conf', 'config', 'sh', 'types', 'js', 'py', 'pyw', 'bat', 'cmd', 'vbs', 'c', 'cpp', 'h', 'java', 'php', 'json', 'xml', 'yaml', 'yml', 'env', 'properties'];
                        Extension_Image      = ['jpg', 'jpeg', 'png', 'gif', 'jfif', 'bmp', 'svg', 'webp'];
                        Extension_Video      = ['mp4', 'avi', 'mov', 'wmv', 'flv', 'mkv', 'webm'];
                        Extension_Audio      = ['mp3', 'wav', 'ogg', 'flac', 'aac', 'ac3', 'dts', 'eac3', 'wma', 'aiff', 'ape', 'tta', 'tak', 'wpl', 'm4a'];
                        Extension_Archive    = ['zip', 'rar', '7z', 'tar', 'gz', 'iso', 'dmg', 'pkg', 'rar', 'tar.gz', 'tar.bz2', 'tar.xz', 'wim'];
                        Extension_Apk        = ['apk', 'xapk', 'appx', 'appxbundle'];
                        Extension_PDF        = ['pdf', 'epub', 'mobi', 'azw3', 'azw', 'azw1', 'azw4', 'azw2', 'fb2', 'docbook', 'djvu'];
                        Extension_Word       = ['doc', 'docx'];
                        Extension_Excel      = ['xls', 'xlsx'];
                        Extension_PowerPoint = ['ppt', 'pptx'];
                        Extension_Disk       = ['vmdk', 'vdi', 'vhd', 'vhdx', 'raw', 'qcow2', 'qcow', 'img', 'pmf'];
                        Extension_Torrent    = ['torrent', 'torrent.gz', 'torrent.bz2', 'torrent.xz', 'torrent.zip', 'torrent.7z', 'torrent.tar', 'torrent.tar.gz', 'torrent.tar.bz2', 'torrent.tar.xz'];
                        
                        // 根据文件类型设置图标
                        if (Extension_Text.includes(extension)) {
                            iconClass = 'fa-file-alt';
                        } else if (Extension_Code.includes(extension)) {
                            iconClass = 'fa-file-code';
                        } else if (Extension_Image.includes(extension)) {
                            iconClass = 'fa-file-image';
                        } else if (Extension_Video.includes(extension)) {
                            iconClass = 'fa-file-video';
                        } else if (Extension_Audio.includes(extension)) {
                            iconClass = 'fa-file-audio';
                        } else if (Extension_Archive.includes(extension)) {
                            iconClass = 'fa-file-archive';
                        } else if (Extension_Apk.includes(extension)) {
                            iconClass = 'fa-archive';
                        } else if (Extension_PDF.includes(extension)) {
                            iconClass = 'fa-file-pdf';
                        } else if (Extension_Word.includes(extension)) {
                            iconClass = 'fa-file-word';
                        } else if (Extension_Excel.includes(extension)) {
                            iconClass = 'fa-file-excel';
                        } else if (Extension_PowerPoint.includes(extension)) {
                            iconClass = 'fa-file-powerpoint';
                        } else if (Extension_Disk.includes(extension)) {
                            iconClass = 'fa-server';
                        } else if (Extension_Torrent.includes(extension)) {
                            iconClass = 'fa-file-download';
                        } else {
                            iconClass = 'fa-file';
                        }
                    } else {
                        if ('ABCDEFGHIJKLMNOPQRSTUVWXYZ'.includes(displayName) && path === '/') {
                            iconClass = 'fa-hdd';
                        } else {
                            iconClass = 'fa-folder';
                        }
                    }
                    
                    // 格式化文件大小
                    let formattedSize = '';
                    if (size !== '' && !isDir) {
                        formattedSize = formatFileSize(parseInt(size));
                    }
                    
                    // 格式化日期
                    let formattedDate = '';
                    if (modified !== '') {
                        formattedDate = new Date(modified).toLocaleString();
                    }
                    
                    fileItem.innerHTML = `
                        <div class="file-icon"><i class="fas ${iconClass}"></i></div>
                        <div class="file-name">${displayName}</div>
                        <div class="file-size">${formattedSize}</div>
                        <div class="file-date">${formattedDate}</div>
                    `;
                    
                    // 添加点击事件
                    fileItem.addEventListener('click', function() {
                        document.querySelectorAll('.file-item').forEach(item => {
                            item.classList.remove('selected');
                        });
                        this.classList.add('selected');
                        selectedFile = this.getAttribute('data-path');
                    });
                    
                    // 添加双击事件
                    fileItem.addEventListener('dblclick', function() {
                        if (isDir) {
                            currentPath = href;
                            loadDirectory(currentPath);
                        } else {
                            if (Extension_Image.includes(extension)) {
                                openImageViewer(displayName, href);
                            } else if (Extension_Video.includes(extension)) {
                                openMediaPlayer(displayName, href, 'video');
                            } else if (Extension_Audio.includes(extension)) {
                                openMediaPlayer(displayName, href, 'audio');
                            } else if (Extension_Text.includes(extension)) {
                                openTextEditor(displayName, href);
                            } else if (Extension_Code.includes(extension)) {
                                openTextEditor(displayName, href);
                            } else {
                                downloadFile(href);
                            }
                        }
                    });
                    
                    fileList.appendChild(fileItem);
                    currentFiles.push({
                        name: displayName,
                        path: href,
                        type: isDir ? 'folder' : 'file',
                        extension: extension
                    });
                }
            }
            
            // 获取上级目录路径
            function getParentPath(path) {
                if (path === '/') return '/';
                const parts = path.split('/').filter(part => part !== '');
                parts.pop();
                return parts.length > 0 ? '/' + parts.join('/') + '/' : '/';
            }
            
            // 格式化文件大小
            function formatFileSize(bytes) {
                if (bytes === 0) return '0 Bytes';
                const k = 1024;
                const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
                const i = Math.floor(Math.log(bytes) / Math.log(k));
                return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
            }
            
            // 打开文本编辑器
            function openTextEditor(filename, filepath) {
                fetch(filepath)
                .then(response => {
                    if (!response.ok) {
                        throw new Error('Network response was not ok');
                    }
                    return response.text();
                })
                .then(text => {
                    document.getElementById('textEditor').value = text;
                    textEditor.style.display = 'block';
                    textEditor.querySelector('.window-title span').textContent = `文本编辑器 - ${decodeURIComponent(filename)}`;
                    textEditor.setAttribute('data-current-file', filepath);
                    textEditor.style.zIndex = 1000;
                    
                    // 降低其他窗口的z-index
                    windows.forEach(w => {
                        if (w !== textEditor) {
                            w.style.zIndex = 1;
                        }
                    });
                })
                .catch(error => {
                    console.error('Error loading file:', error);
                    toastr.error('加载文件失败: ' + error.message);
                });
            }

            const videoPlayer   = document.getElementById('videoPlayer');
            const playBtn       = document.getElementById('playBtn');
            const muteBtn       = document.getElementById('muteBtn');
            const volumeSlider  = document.getElementById('volumeSlider');
            const progressBar   = document.getElementById('progress');
            const currentTime   = document.getElementById('currentTime');
            const totalTime     = document.getElementById('totalTime');
            const fullscreenBtn = document.getElementById('fullscreenMediaBtn');

            // 格式化时间
            function formatTime(seconds) {
                const  mins = Math.floor(seconds / 60);
                const  secs = Math.floor(seconds % 60);
                return mins + ':' + (secs < 10 ? '0' : '') + secs;
            }
            
            // 打开媒体播放器
            function openMediaPlayer(filename, filepath, type) {
                removeMediaPlayerEventListeners();
                const mediaPlayerTitle = document.getElementById('mediaPlayerWindowTitle');
                const mediaPlayer      = document.getElementById('mediaPlayerWindow');
                const videoPlayer      = document.getElementById('videoPlayer');
                const audioContainer   = document.getElementById('audioContainer');
                const videoContainer   = document.getElementById('videoContainer');
                const videoPlaceholder = document.getElementById('videoPlaceholder');
                const fullscreenBtn    = document.getElementById('fullscreenMediaBtn');
                const progressBar      = document.getElementById('progress')
                const mediaInfo        = document.getElementById('mediaInfo');
                let   audioPlayer      = document.getElementById('audioPlayer');
                if (audioPlayer) {
                    audioPlayer.pause();
                    audioPlayer.src = '';
                    audioPlayer.remove();
                }
                if (type === 'video') {
                    fullscreenBtn.style.display = 'block';
                    progressBar.style.width     = '0%';
                    mediaPlayer.style.width     = '100vh';
                    mediaPlayer.style.height    = '85vh';
                    videoPlayer.style.display      = 'block';
                    videoContainer.style.display   = 'flex';
                    videoPlaceholder.style.display = 'none';
                    audioContainer.style.display   = 'none';
                    videoPlayer.src = filepath;
                    fullscreenBtn.addEventListener('click', function() {
                        if (videoPlayer.requestFullscreen) {
                            videoPlayer.requestFullscreen();
                        } else if (videoPlayer.webkitRequestFullscreen) {
                            videoPlayer.webkitRequestFullscreen();
                        } else if (videoPlayer.msRequestFullscreen) {
                            videoPlayer.msRequestFullscreen();
                        }
                    });
                    setupVideoPlayer();
                } else {
                    fullscreenBtn.style.display = 'none';
                    progressBar.style.width     = '0%';
                    mediaPlayer.style.width     = '80vh';
                    mediaPlayer.style.height    = '32vh';
                    videoPlayer.style.display      = 'none';
                    videoContainer.style.display   = 'none';
                    videoPlaceholder.style.display = 'none';
                    audioContainer.style.display   = 'flex';

                    audioPlayer = document.createElement('audio');
                    audioPlayer.id = 'audioPlayer';
                    audioPlayer.style.display = 'none';
                    document.body.appendChild(audioPlayer);
                    
                    videoPlayer.src = '';
                    audioPlayer.src = filepath;
                    setupAudioPlayer(audioPlayer);
                }

                mediaPlayerTitle.innerHTML = `媒体播放器 - ${decodeURIComponent(filename)}`;
                mediaInfo.textContent = filename;
                mediaPlayer.style.display = 'block';
                mediaPlayer.setAttribute('data-current-file', filepath);

                mediaPlayer.style.zIndex = 1000;
                    
                // 降低其他窗口的z-index
                windows.forEach(w => {
                    if (w !== mediaPlayer) {
                        w.style.zIndex = 1;
                    }
                });
            }
            
            // 设置音频播放器事件
            function setupAudioPlayer(audioPlayer) {
                const volumeSlider = document.getElementById('volumeSlider');
                const progressBar  = document.getElementById('progress');
                const currentTime  = document.getElementById('currentTime');
                const totalTime    = document.getElementById('totalTime');
                const playBtn = document.getElementById('playBtn');
                const prevBtn = document.getElementById('prevBtn');
                const nextBtn = document.getElementById('nextBtn');
                const muteBtn = document.getElementById('muteBtn');
                
                playBtn.addEventListener('click', function() {
                    if (audioPlayer.paused) {
                        audioPlayer.play();
                        playBtn.innerHTML = '<i class="fas fa-pause"></i>';
                    } else {
                        audioPlayer.pause();
                        playBtn.innerHTML = '<i class="fas fa-play"></i>';
                    }
                });

                prevBtn.addEventListener('click', function() {
                    audioPlayer.currentTime -= 2;
                });
                
                nextBtn.addEventListener('click', function() {
                    audioPlayer.currentTime += 2;
                });
                
                muteBtn.addEventListener('click', function() {
                    audioPlayer.muted = !audioPlayer.muted;
                    muteBtn.innerHTML =  audioPlayer.muted? 
                        '<i class="fas fa-volume-mute"></i>' : 
                        '<i class="fas fa-volume-up"></i>';
                });
                
                volumeSlider.addEventListener('input', function() {
                    audioPlayer.volume = volumeSlider.value;
                });
                
                document.getElementById('progressBar').addEventListener('click', function(e) {
                    const progressBar   = e.currentTarget;
                    const clickPosition = e.clientX - progressBar.getBoundingClientRect().left;
                    const progressBarWidth  = progressBar.offsetWidth;
                    const percentage        = clickPosition / progressBarWidth;
                    audioPlayer.currentTime = percentage * audioPlayer.duration;
                });
                
                // 更新进度条和时间显示
                audioPlayer.addEventListener('timeupdate', function() {
                    const current  = audioPlayer.currentTime;
                    const duration = audioPlayer.duration;
                    
                    // 更新视频进度条
                    const progressPercentage = (current / duration) * 100;
                    progressBar.style.width  = progressPercentage + '%';
                    
                    // 更新时间显示
                    currentTime.textContent = formatTime(current);
                    totalTime.textContent   = formatTime(duration);
                });
                
                // 音频加载完成
                audioPlayer.addEventListener('loadedmetadata', function() {
                    totalTime.textContent = formatTime(audioPlayer.duration);
                    document.getElementById('playBtn').innerHTML = '<i class="fas fa-pause"></i>';
                    this.currentTime = 0;
                    this.play();
                });
                
                // 音频播放结束
                audioPlayer.addEventListener('ended', function() {
                    document.getElementById('playBtn').innerHTML = '<i class="fas fa-pause"></i>';
                    this.currentTime = 0;
                    this.play();
                });
            }

            // 设置视频播放器事件
            function setupVideoPlayer() {
                const videoPlayer   = document.getElementById('videoPlayer');
                const playBtn       = document.getElementById('playBtn');
                const muteBtn       = document.getElementById('muteBtn');
                const prevBtn       = document.getElementById('prevBtn');
                const nextBtn       = document.getElementById('nextBtn');
                const volumeSlider  = document.getElementById('volumeSlider');
                const progressBar   = document.getElementById('progress');
                const currentTime   = document.getElementById('currentTime');
                const totalTime     = document.getElementById('totalTime');

                prevBtn.addEventListener('click', function() {
                    videoPlayer.currentTime -= 5;
                });
                
                nextBtn.addEventListener('click', function() {
                    videoPlayer.currentTime += 5;
                });
            
                playBtn.addEventListener('click', function() {
                    if (videoPlayer.paused) {
                        videoPlayer.play();
                        playBtn.innerHTML = '<i class="fas fa-pause"></i>';
                    } else {
                        videoPlayer.pause();
                        playBtn.innerHTML = '<i class="fas fa-play"></i>';
                    }
                });
                
                muteBtn.addEventListener('click', function() {
                    videoPlayer.muted = !videoPlayer.muted;
                    muteBtn.innerHTML =  videoPlayer.muted? 
                        '<i class="fas fa-volume-mute"></i>' : 
                        '<i class="fas fa-volume-up"></i>'   ;
                });
                
                volumeSlider.addEventListener('input', function() {
                    videoPlayer.volume = volumeSlider.value;
                });
                
                document.getElementById('progressBar').addEventListener('click', function(e) {
                    const progressBar       = e.currentTarget;
                    const clickPosition     = e.clientX - progressBar.getBoundingClientRect().left;
                    const progressBarWidth  = progressBar.offsetWidth;
                    const percentage        = clickPosition / progressBarWidth;
                    videoPlayer.currentTime = percentage * videoPlayer.duration;
                });
                
                videoPlayer.addEventListener('timeupdate', function() {
                    const current            = videoPlayer.currentTime;
                    const duration           = videoPlayer.duration;
                    const progressPercentage = (current / duration) * 100;
                    progressBar.style.width  = progressPercentage + '%';
                    currentTime.textContent  = formatTime(current);
                    totalTime.textContent    = formatTime(duration);
                });
                
                videoPlayer.addEventListener('loadedmetadata', function() {
                    totalTime.textContent = formatTime(videoPlayer.duration);
                    document.getElementById('playBtn').innerHTML = '<i class="fas fa-pause"></i>';
                    this.currentTime = 0;
                    this.play();
                });
                
                videoPlayer.addEventListener('ended', function() {
                    document.getElementById('playBtn').innerHTML = '<i class="fas fa-pause"></i>';
                    this.currentTime = 0;
                    this.play();
                });
            }

            function removeEventListeners(element) {
                if (element){
                    element.parentNode.replaceChild(element.cloneNode(true), element);
                }
            }

            function removeMediaPlayerEventListeners() {
                removeEventListeners(document.getElementById('playBtn'));
                removeEventListeners(document.getElementById('prevBtn'));
                removeEventListeners(document.getElementById('nextBtn'));
                removeEventListeners(document.getElementById('muteBtn'));
                removeEventListeners(document.getElementById('progressBar'));
                removeEventListeners(document.getElementById('videoPlayer'));
                removeEventListeners(document.getElementById('audioPlayer'));
                removeEventListeners(document.getElementById('volumeSlider'));
            }

            // 打开图片查看器
            function openImageViewer(filename, filepath) {
                const imageViewer = document.getElementById('imageViewer');
                const imagePlaceholder = document.getElementById('imagePlaceholder');
                
                imageViewer.style.display = 'block';
                imagePlaceholder.style.display = 'none';
                imageViewer.src = filepath;
                imageViewerWindow.style.display = 'block';
                imageViewerWindow.setAttribute('data-current-file', filepath);

                imageViewer.style.zIndex = 1000;
                    
                // 降低其他窗口的z-index
                windows.forEach(w => {
                    if (w !== imageViewer) {
                        w.style.zIndex = 1;
                    }
                });
            }
            
            // 下载文件/文件夹
            function downloadFile(filepath) {
                const a = document.createElement('a');
                if(filepath.endsWith('/')){
                    a.href = filepath + '?zip';
                } else {
                    a.href = filepath + '?download';
                }
                a.download = filepath.split('/').pop();
                a.click();
                a.remove();
                if(filepath.endsWith('/')){
                    fetch(filepath + '?size', {
                        method: 'GET',
                    })
                    .then(response => {
                        if (!response.ok) {
                            throw new Error('Network response was not ok');
                        }
                        return response.text();
                    })
                    .then(text => {
                        const size = parseInt(text);
                        const sizeStr = formatFileSize(size);
                        toastr.success(`文件夹已开始下载 (${sizeStr})`);
                    })
                    .catch(error => {
                        console.error('Error loading file size:', error);
                        toastr.success('文件夹已开始下载');
                    });
                } else {
                    toastr.success('文件已开始下载');
                }
            }
            
            document.getElementById('refreshBtn').addEventListener('click', function() {
                loadDirectory(currentPath);
            });
            
            document.getElementById('downloadBtn').addEventListener('click', function() {
                if (selectedFile) {
                    downloadFile(selectedFile);
                } else {
                    toastr.warning('请先选择一个文件');
                }
            });
            
            document.getElementById('deleteBtn').addEventListener('click', function() {
                if (selectedFile) {
                    if ('ABCDEFGHIJKLMNOPQRSTUVWXYZ'.includes(selectedFile.replace('/', '').replace('/', ''))) {
                        toastr.warning('不能删除整个磁盘');
                        return;
                    }
                    showConfirm("确定要删除选中的项目吗？", function(result) {
                        if (result) {
                            fetch(selectedFile, {
                                method: 'DELETE'
                            })
                            .then(response => {
                                if (response.ok) {
                                    toastr.success('文件删除成功');
                                    loadDirectory(currentPath);
                                } else {
                                    toastr.error('删除失败');
                                }
                            })
                            .catch(error => {
                                console.error('Error deleting file:', error);
                                toastr.error('删除失败: ' + error.message);
                            });
                        }
                    });
                } else {
                    toastr.warning('请先选择一个文件/文件夹');
                }
            });
            
            // 文本编辑器按钮事件
            document.getElementById('saveFileBtn').addEventListener('click', function() {
                const content  = document.getElementById('textEditor').value;
                const filepath = textEditor.getAttribute('data-current-file');
                
                fetch(filepath, {
                    method: 'PUT',
                    body: content
                })
                .then(response => {
                    if (response.ok) {
                        loadDirectory(currentPath);
                        toastr.success('文件保存成功');
                    } else {
                        toastr.error('保存失败');
                    }
                })
                .catch(error => {
                    console.error('Error saving file:', error);
                    toastr.error('保存失败: ' + error.message);
                });
            });
            
            document.getElementById('cancelEditBtn').addEventListener('click', function() {
                textEditor.style.display = 'none';
            });
            
            // 添加上传队列数组
            let uploadQueue = [];

            // 修改上传按钮事件处理
            document.getElementById('uploadBtn').addEventListener('click', function() {
                const uploadInput = document.getElementById('uploadInput');
                uploadInput.value = '';
                uploadInput.click();
            });

            // 添加上传列表显示/隐藏功能
            document.getElementById('uploadBtn').addEventListener('mouseenter', function() {
                if (uploadQueue.length > 0) {
                    document.getElementById('uploadListContainer').style.display = 'block';
                }
            });

            document.getElementById('uploadListClose').addEventListener('click', function() {
                document.getElementById('uploadListContainer').style.display = 'none';
            });

            // 修改文件选择处理
            document.getElementById('uploadInput').addEventListener('change', function() {
                const files = this.files;
                if (files.length > 0) {
                    // 显示上传列表
                    document.getElementById('uploadListContainer').style.display = 'block';
                    
                    // 处理每个文件
                    Array.from(files).forEach(file => {
                        addFileToUploadQueue(file);
                    });
                    
                    // 开始上传
                    processUploadQueue();
                }
            });

            // 添加上传队列管理函数
            function addFileToUploadQueue(file) {
                const uploadId = Date.now() + Math.random().toString(36).substr(2, 5);
                
                const uploadItem = {
                    id: uploadId,
                    file: file,
                    progress: 0,
                    status: 'pending', // pending, uploading, completed, error
                    error: null
                };
                
                uploadQueue.push(uploadItem);
                
                // 添加上传项目到UI
                const uploadListItems = document.getElementById('uploadListItems');
                const uploadItemElement = document.createElement('div');
                uploadItemElement.className = 'upload-item';
                uploadItemElement.id = `upload-item-${uploadId}`;
                uploadItemElement.innerHTML = `
                    <div class="upload-item-info">
                        <div class="upload-item-name" title="${file.name}">${file.name}</div>
                        <div class="upload-item-percent">0%</div>
                    </div>
                    <div class="upload-progress-container">
                        <div class="upload-progress-bar" id="progress-bar-${uploadId}"></div>
                    </div>
                    <div class="upload-item-error" id="upload-error-${uploadId}"></div>
                `;
                
                uploadListItems.appendChild(uploadItemElement);
            }

            function processUploadQueue() {
                // 查找待处理的上传
                const pendingUpload = uploadQueue.find(item => item.status === 'pending');
                
                if (pendingUpload) {
                    // 更新状态为上传中
                    pendingUpload.status = 'uploading';
                    
                    // 执行实际上传
                    uploadFile(pendingUpload);
                }
            }

            function uploadFile(uploadItem) {
                const filePath = currentPath + (currentPath.endsWith('/') ? '' : '/') + uploadItem.file.name;
                const xhr = new XMLHttpRequest();
                
                // 进度事件处理
                xhr.upload.addEventListener('progress', function(e) {
                    if (e.lengthComputable) {
                        const percentComplete = (e.loaded / e.total) * 100;
                        updateUploadProgress(uploadItem.id, percentComplete);
                    }
                });
                
                // 完成事件处理
                xhr.addEventListener('load', function() {
                    if (xhr.status >= 200 && xhr.status < 300) {
                        // 上传成功
                        updateUploadStatus(uploadItem.id, 'completed', 100);
                        
                        // 刷新文件列表
                        loadDirectory(currentPath);
                        
                        // 处理下一个上传
                        setTimeout(processUploadQueue, 500);
                    } else {
                        // 上传失败
                        updateUploadStatus(uploadItem.id, 'error', null, '上传失败: ' + xhr.statusText);
                        setTimeout(processUploadQueue, 500);
                    }
                });
                
                // 错误事件处理
                xhr.addEventListener('error', function() {
                    updateUploadStatus(uploadItem.id, 'error', null, '网络错误');
                    setTimeout(processUploadQueue, 500);
                });
                
                // 中止事件处理
                xhr.addEventListener('abort', function() {
                    updateUploadStatus(uploadItem.id, 'error', null, '上传已取消');
                    setTimeout(processUploadQueue, 500);
                });
                
                // 开始上传
                xhr.open('PUT', filePath, true);
                xhr.send(uploadItem.file);
            }

            function updateUploadProgress(uploadId, progress) {
                // 如果是文件夹上传（ID以dir-开头）
                if (uploadId.startsWith('dir-')) {
                    const progressBar = document.getElementById(`progress-bar-${uploadId}`);
                    if (progressBar) {
                        progressBar.style.width = `${progress}%`;
                    }
                } else {
                    // 更新队列中的项目
                    const uploadItem = uploadQueue.find(item => item.id === uploadId);
                    if (uploadItem) {
                        uploadItem.progress = progress;
                    }
                    
                    // 更新UI
                    const progressBar = document.getElementById(`progress-bar-${uploadId}`);
                    const percentText = document.querySelector(`#upload-item-${uploadId} .upload-item-percent`);
                    
                    if (progressBar && percentText) {
                        progressBar.style.width = `${progress}%`;
                        percentText.textContent = `${Math.round(progress)}%`;
                    }
                }
            }

            function updateUploadStatus(uploadId, status, progress, errorMessage) {
                // 如果是文件夹上传（ID以dir-开头）
                if (uploadId.startsWith('dir-')) {
                    const uploadItem = uploadQueue.find(item => item.id === uploadId);
                    if (uploadItem) {
                        uploadItem.status = status;
                        if (progress !== null) {
                            uploadItem.progress = progress;
                        }
                        if (errorMessage) {
                            uploadItem.error = errorMessage;
                        }
                    }
                    
                    const errorElement = document.getElementById(`upload-error-${uploadId}`);
                    if (errorElement && errorMessage) {
                        errorElement.textContent = errorMessage;
                    }
                    
                    if (status === 'completed') {
                        const uploadItemElement = document.getElementById(`upload-item-${uploadId}`);
                        if (uploadItemElement) {
                            uploadItemElement.style.opacity = '0.7';
                            
                            // 3秒后移除已完成的项目
                            setTimeout(() => {
                                if (uploadItemElement.parentNode) {
                                    uploadItemElement.parentNode.removeChild(uploadItemElement);
                                    
                                    // 从队列中移除
                                    uploadQueue = uploadQueue.filter(item => item.id !== uploadId);
                                    
                                    // 如果队列为空，隐藏上传列表
                                    if (uploadQueue.length === 0) {
                                        document.getElementById('uploadListContainer').style.display = 'none';
                                    }
                                }
                            }, 3000);
                        }
                    }
                } else {
                    // 更新队列中的项目
                    const uploadItem = uploadQueue.find(item => item.id === uploadId);
                    if (uploadItem) {
                        uploadItem.status = status;
                        if (progress !== null) {
                            uploadItem.progress = progress;
                        }
                        if (errorMessage) {
                            uploadItem.error = errorMessage;
                        }
                    }
                    
                    // 更新UI
                    if (status === 'completed') {
                        updateUploadProgress(uploadId, 100);
                        const uploadItemElement = document.getElementById(`upload-item-${uploadId}`);
                        if (uploadItemElement) {
                            uploadItemElement.style.opacity = '0.7';
                            
                            // 3秒后移除已完成的项目
                            setTimeout(() => {
                                if (uploadItemElement.parentNode) {
                                    uploadItemElement.parentNode.removeChild(uploadItemElement);
                                    
                                    // 从队列中移除
                                    uploadQueue = uploadQueue.filter(item => item.id !== uploadId);
                                    
                                    // 如果队列为空，隐藏上传列表
                                    if (uploadQueue.length === 0) {
                                        document.getElementById('uploadListContainer').style.display = 'none';
                                    }
                                }
                            }, 3000);
                        }
                    } else if (status === 'error') {
                        const errorElement = document.getElementById(`upload-error-${uploadId}`);
                        if (errorElement && errorMessage) {
                            errorElement.textContent = errorMessage;
                        }
                    }
                }
            }

            // 添加上传列表关闭功能
            document.getElementById('uploadListClose').addEventListener('click', function() {
                document.getElementById('uploadListContainer').style.display = 'none';
            });

            document.getElementById('createFileBtn').addEventListener('click', function() {
                showPrompt('请输入文件名称:', '新建文件.txt', function(value) {
                    if (value !== null) {
                        const filePath = currentPath + (currentPath.endsWith('/') ? '' : '/') + value;
                        fetch(filePath, {
                            method: 'PUT',
                            body: ''
                        })
                        .then(response => {
                            if (response.ok) {
                                toastr.success('文件创建成功');
                                loadDirectory(currentPath);
                            } else {
                                toastr.error('创建文件失败');
                            }
                        })
                        .catch(error => {
                            console.error('Error creating file:', error);
                            toastr.error('创建文件失败: ' + error.message);
                        });
                    }
                });
            });

            document.getElementById('renameBtn').addEventListener('click', function() {
                if (selectedFile) {
                    showPrompt('请输入新名称:', selectedFile, function(value) {
                        if (value === selectedFile) {
                            toastr.warning('新名称不能与原名称相同');
                            return;
                        }
                        if (value !== null) {
                            fetch(selectedFile, {
                                method: 'MOVE',
                                headers: {
                                    'Destination': encodeURIComponent(value)
                                }
                            })
                            .then(response => {
                                if (response.ok) {
                                    toastr.success('文件重命名成功');
                                    loadDirectory(currentPath);
                                } else {
                                    toastr.error('重命名失败');
                                }
                            })
                            .catch(error => {
                                console.error('Error renaming file:', error);
                                toastr.error('重命名失败: ' + error.message);
                            });
                        }
                    });
                } else {
                    toastr.warning('请先选择一个文件/文件夹');
                }
            });
            // 新建文件夹按钮
            document.getElementById('createFolderBtn').addEventListener('click', function() {
                showPrompt('请输入文件夹名称:', '新建文件夹', function(value) {
                    if (value !== null) {
                        const folderPath = currentPath + (currentPath.endsWith('/') ? '' : '/') + value;
                        fetch(folderPath, {
                            method: 'MKCOL'
                        })
                        .then(response => {
                            if (response.ok) {
                                loadDirectory(currentPath);
                            } else {
                                toastr.error('创建文件夹失败');
                            }
                        })
                        .catch(error => {
                            console.error('Error creating folder:', error);
                            toastr.error('创建文件夹失败: ' + error.message);
                        });
                    }
                });
            });
            setInterval(function() {
                const videoPlayer = document.getElementById('videoPlayer');
                const audioPlayer = document.getElementById('audioPlayer');
                const playBtn     = document.getElementById('playBtn');
                if (videoPlayer && videoPlayer.src != ''){
                    playBtn.innerHTML = videoPlayer.paused ? '<i class="fas fa-play"></i>' : '<i class="fas fa-pause"></i>';
                }
                if (audioPlayer && audioPlayer.src != ''){
                    playBtn.innerHTML = audioPlayer.paused ? '<i class="fas fa-play"></i>' : '<i class="fas fa-pause"></i>';
                }
            }, 200);
        });
        document.getElementById('LogoutBtn').addEventListener('click', function(e) {
            e.preventDefault();
            fetch('/', {
                method: 'LOGOUT'
            })
            .then(response => {
                if (response.ok) {
                    window.location.replace((window.location.pathname + '/').replace('//', '/'));
                } else {
                    toastr.error('登出失败');
                }
            })
            .catch(error => {
                console.error('Error logging out:', error);
                toastr.error('登出失败: ' + error.message);
            });
        });
    </script>
</body>
</html>